//
//  WhsEditWhsViewController.m
//  HAODE
//
//  Created by panquanReabam.com on 16/1/26.
//  Copyright © 2016年 reabam.com. All rights reserved.
//

#import "TheEditingViewController.h"
#import "UIViewExt.h"
#import "HttpRequest.h"
@interface TheEditingViewController ()<UISearchBarDelegate,UITextFieldDelegate>

@end

@implementation TheEditingViewController

{
    UITextField*whsTextFied;
    UIButton*jiantou;
}

@synthesize alt = alt;


-(void)viewDidLoad{
    
    [super viewDidLoad];
}
-(void)BackAction:(UIButton *)sender{
    
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewDidDisappear:(BOOL)animated

{
    
    [super viewDidDisappear:animated];
    
    self.navigationController.delegate = nil;
    
}



-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(0,0,30,30);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.font=[UIFont systemFontOfSize:13];
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    
    self.title=self.titleName;
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                     [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1.0],
                                                                     UITextAttributeTextColor,
                                                                     [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1],
                                                                     UITextAttributeTextShadowColor,
                                                                     [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
                                                                     UITextAttributeTextShadowOffset,
                                                                     [UIFont fontWithName:@"Helvetica Neue" size:tetlefot],
                                                                     UITextAttributeFont,nil]];
 
    
    self.view.backgroundColor=zuiqianhuiColor;
    
    
    
    if ([self.type isEqualToString:@"sex"]) {
        UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 64+10, ScreenWidth, 100)];
        view.backgroundColor=[UIColor whiteColor];
        view.layer.borderWidth = 0.40;
        view.layer.borderColor = qianhuiColor.CGColor;
        [self.view addSubview:view];
        UIButton*male = [[UIButton alloc] initWithFrame:CGRectMake(15, 0.0,  ScreenWidth, 50)];
        [male setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [male setTitle:@"男" forState:UIControlStateNormal];
        male.titleLabel.font=[UIFont systemFontOfSize:16];
        male.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
        [male addTarget:self action:@selector(male:) forControlEvents:UIControlEventTouchUpInside];
        
        [view addSubview:male];
        UILabel*line=[[UILabel alloc]initWithFrame:CGRectMake(0, 50, ScreenWidth, 0.40)];
        line.backgroundColor=qianhuiColor;
        [view addSubview:line];
        
        UIButton*female = [[UIButton alloc] initWithFrame:CGRectMake(15, 50,  ScreenWidth, 50)];
        [female setTitleColor:[UIColor blackColor]  forState:UIControlStateNormal];
        [female setTitle:@"女" forState:UIControlStateNormal];
        female.titleLabel.font=[UIFont systemFontOfSize:16];
        female.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
        [female addTarget:self action:@selector(female:) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:female];

        if ( [self.sexStr  isEqualToString: @"男"]) {
            jiantou = [[UIButton alloc]init];
            jiantou.frame = CGRectMake(ScreenWidth-45,10, 30, 30);
            [jiantou setImage:[UIImage imageNamed:@"huiyuan_gou"] forState:UIControlStateNormal];
            [view addSubview:jiantou];
        }else{
            jiantou = [[UIButton alloc]init];
            jiantou.frame = CGRectMake(ScreenWidth-45,10+50, 30, 30);
            [jiantou setImage:[UIImage imageNamed:@"huiyuan_gou"] forState:UIControlStateNormal];
            [view addSubview:jiantou];
        
        }
       

    }else{
    
        UIButton*saveBtn = [[UIButton alloc] initWithFrame:CGRectMake(30, 0.0,  35,35)];
        [saveBtn setTitleColor:luseColor forState:UIControlStateNormal];
        [saveBtn setTitle:@"保存" forState:UIControlStateNormal];
        saveBtn.titleLabel.font=[UIFont systemFontOfSize:16];
        [saveBtn addTarget:self action:@selector(save:) forControlEvents:UIControlEventTouchUpInside];
        UIBarButtonItem* myBtnBtn = [[UIBarButtonItem alloc] initWithCustomView:saveBtn];
        self.navigationItem.rightBarButtonItem = myBtnBtn;

        UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 64+10, ScreenWidth, 50)];
        view.backgroundColor=[UIColor whiteColor];
        view.layer.borderWidth = 0.40;
        view.layer.borderColor = qianhuiColor.CGColor;
        [self.view addSubview:view];
    
    
   
        whsTextFied=[[UITextField alloc]initWithFrame:CGRectMake(15, 0, ScreenWidth-30,  50)];
        whsTextFied.borderStyle = UITextBorderStyleNone;
        whsTextFied.font = [UIFont systemFontOfSize: contenfot];
        whsTextFied.textColor=[UIColor blackColor];
        whsTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
        
        if ([self.type isEqualToString:@"userName"]) {
         whsTextFied.text=self.userNameStr;
           whsTextFied.placeholder = @" 请输入姓名"; //默认显示的字
        }
        if ([self.type isEqualToString:@"memo"]) {
         whsTextFied.text=self.memoStr;
           whsTextFied.placeholder = @" 请输入备注"; //默认显示的字
        
        }
        [whsTextFied becomeFirstResponder];
   
    [whsTextFied setUserInteractionEnabled:YES];
    whsTextFied.delegate = self;
 
    whsTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
    [view addSubview:whsTextFied];
    }
    
    
    UIView* myToolBar=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, viewheight)];
    myToolBar.backgroundColor=jianpancolor;
    UIButton*  tubtnDone=[[UIButton alloc]initWithFrame:CGRectMake(logoX,logoY, logoheight, logowidth)];
    [tubtnDone setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [tubtnDone addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:tubtnDone];
    UIButton*btnDone=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width - 55, 12, 40, 16)];
    [btnDone setTitle:@"确定" forState:UIControlStateNormal];
    [btnDone setTitleColor:jianpancolor1 forState:UIControlStateNormal];
    btnDone .titleLabel .font=[UIFont systemFontOfSize:keyboardFot];
    [btnDone addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:btnDone];
    myToolBar.alpha=alp;
    UIButton* dabtn=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width-60, 0, 60, 40)];
    [dabtn addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:dabtn];
    
    whsTextFied.inputAccessoryView = myToolBar;
    
    
    
    
}

-(void)OnTapDone{
    
    [whsTextFied resignFirstResponder];
    
    
}

-(void)male:(UIButton*)sender{

    self.sexStr=@"男";
    jiantou.frame = CGRectMake(ScreenWidth-45,10, 30, 30);
    [self.delegate secondViewController:self updateUserNameText:self.userNameStr updateSexStr:self.sexStr updateMemoStr:self.memoStr];
    [self.navigationController popViewControllerAnimated:YES];


}
-(void)female:(UIButton*)sender{

    self.sexStr=@"女";
    jiantou.frame = CGRectMake(ScreenWidth-45,10+50, 30, 30);
    [self.delegate secondViewController:self updateUserNameText:self.userNameStr updateSexStr:self.sexStr updateMemoStr:self.memoStr];
    [self.navigationController popViewControllerAnimated:YES];

}
-(void)save:(UIButton*)sender{

if ([self.type isEqualToString:@"userName"]) {
       
[self.delegate secondViewController:self updateUserNameText:whsTextFied.text updateSexStr:self.sexStr updateMemoStr:self.memoStr];
    }
if ([self.type isEqualToString:@"sex"]) {
  [self.delegate secondViewController:self updateUserNameText:self.userNameStr updateSexStr:self.sexStr updateMemoStr:self.memoStr];
    }
if ([self.type isEqualToString:@"memo"]) {
  [self.delegate secondViewController:self updateUserNameText:self.userNameStr updateSexStr:self.sexStr updateMemoStr:whsTextFied.text];
}
     [self performSelector:@selector(load) withObject:nil afterDelay:1.5f];

}
- (void)load
{
[self.navigationController popViewControllerAnimated:YES];

}
- (void)showAlertWait
{
    alt = [[UIAlertView alloc] initWithTitle:@"网络不稳定 ！" message:@"请确认网络" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
    
}

- (void)showAlertMessage:(NSString *)msg

{
    alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
}
- (void)hideAlert
{
    if (alt != nil)
    {
        [alt dismissWithClickedButtonIndex:0 animated:YES];
        alt = nil;
    }
}

@end
